import subprocess

def check_service(service_name):# 这里ServiceName可以是任何systemctl能够识别的,因此查看Nginx时可以时nginx,但MySQL只能时mysqld
    output = subprocess.check_output(['service', service_name, 'status'], stderr=subprocess.STDOUT)
    return 'active (running)' in output# 返回项目的状态,true或者false